<?php

namespace App\Console\Commands;

use Dcat\Admin\Models\Menu;
use Illuminate\Console\Command;

class AdminMenu extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'admin:menu';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create Admin Menu';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $menus = require app_path("Admin/menu.php");

        $this->createMenu($menus,0);
    }


    public function createMenu($arr,$pid)
    {
        $order = 1;
        foreach ($arr as $row){
            $row["parent_id"] = $pid;
            $row["order"] = $order++;
            $menu = Menu::create($row);
            if(isset($row["children"]) && count($row["children"]) > 0){
                $this->createMenu($row["children"],$menu->id);
            }
        }
    }
}
